<template>
  <el-drawer
    :visible.sync="drawer"
    direction="rtl"
    size="50%"
    :with-header="false"
    :width="700"
    append-to-body
  >
    <div class="drawer_box">
      <div class="drawer_title">
        <div class="drawer_t">
          <div class="drawer_t_l">添加权益</div>
          <img
            class="drawer_t_r"
            src="../../../../../static/skin/herodoo/main/platform/home/img/guanbi.png"
            alt=""
            @click="drawer = false"
          />
        </div>
      </div>
      <div class="drawer_content">
        <el-table
          ref="multipleTable"
          v-loading="dataListLoading"
          :data="cancelList"
          :row-key="getRowKeys"
          @selection-change="handleSelectionChange"
          style="width: 100%; font-size: 1rem"
        >
          <el-table-column
            type="selection"
            :reserve-selection="true"
          ></el-table-column>
          <el-table-column prop="VerificeCode" label="核销码"></el-table-column>
          <el-table-column prop="Name" label="核销金额(元)"></el-table-column>
          <el-table-column prop="ID" label="核销时间"></el-table-column>
        </el-table>
        <div class="end" v-if="total > 0">
          <el-pagination
            background
            layout="prev, pager, next"
            :total="total"
            :current-page="currentPage"
            :page-size="pageSize"
            @current-change="handleCurrentChange"
          >
          </el-pagination>
        </div>
      </div>

      <div class="drawer_footer">
        <div class="select-num">
          已选择权益<span>{{ multipleSelection.length }}</span
          >件
        </div>
        <div class="add-money">
          合计<span>￥{{ money.toFixed(2) }}</span>
        </div>
        <button class="footer-btn" @click="handleSelection">确认</button>
      </div>
    </div>
  </el-drawer>
</template>

<script>
export default {
  props: {
    orderId: {
      type: [String, Number],
      default: "",
    },
    octopus: {
      type: Object,
      default: {},
    },
    // 默认选中的列
    checkList: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      drawer: false,
      cancelList: [],
      multipleSelection: [],
      total: 0,
      currentPage: 1, //当前页
      pageSize: 20, // 每页显示条数
      dataListLoading: true,
    };
  },
  computed: {
    money() {
      let num = 0
      this.multipleSelection.map(item => {
        num += item.ID
      })
      return num
    }
  },
  watch: {
    drawer(v) {
      if (v) {
        this.cancelList = []
        this.getCancelList();
        // 默认选中
        this.$nextTick(() => {
          this.checkList.map((item) => {
            this.$refs.multipleTable.toggleRowSelection(
              this.cancelList[item],
              true
            );
          });
        });
      }
    },
  },
  methods: {
    drawerOp() {
      this.drawer = true;
    },
    // 核销列表
    getCancelList() {
      this.cancelList.push({
        VerificeCode: "1212",
        Name: "111",
        ID: 1,
      });
      this.cancelList.push({
        VerificeCode: "1212",
        Name: "111",
        ID: 2,
      });
      this.cancelList.push({
        VerificeCode: "1212",
        Name: "111",
        ID: 3,
      });
      this.dataListLoading = false
      return
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1243,
          cellData: [
            { name: "EquityName" }, // 权益名称
            { name: "ID" }, // ID
            { name: "PurchaserName" }, // 买家
            { name: "Status" }, // 使用状态
            { name: "VerificeCode" }, // 核销码
          ],
          paramData: {
            ID: this.messageList.ID,
          },
          pageData: {
            index: this.currentPage,
            rowSize: this.pageSize,
          },
        },
        (data) => {
          if (data.status.code == 200) {
            this.total = data.content.pageData.totalRows;
            this.concelList = data.content.queryData;
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    getRowKeys(row) {
      return row.ID;
    },
    handleSelectionChange(selection) {
      console.log(selection);
      this.multipleSelection = selection;
    },
    // 选择开票权益
    handleSelection() {
      this.$emit("invoiceList", this.multipleSelection);
    },
  },
};
</script>
<style scoped>
.drawer_box {
  padding: 3rem 0.8rem 3rem 0;
  height: calc(100% - 5rem);
  display: flex;
  flex-direction: column;
}

.drawer_title {
  box-shadow: 0px 5px 5px rgb(230 228 228 / 30%);
  padding-bottom: 1rem;
}

.drawer_t {
  padding: 0 2.8rem;
  display: flex;
  justify-content: space-between;
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 2rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 2.8rem;
  margin-right: 1rem;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
}

.button_box {
  margin-top: 1rem;
  padding: 0 3rem;
  display: flex;
}

.drawer_content {
  overflow-y: auto;
  margin-top: 1.5rem;
  height: calc(100vh - 11rem);
  padding: 0 3rem;
  width: 100%;
  padding-bottom: 1rem;
}

.drawer_content .title {
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_content .driver-title {
  margin-top: 1em;
}
.full-line {
  margin: 2rem auto;
  width: 95%;
  height: 1px;
  background-color: #f78c51;
}

.content-box {
  display: flex;
  align-items: center;
  margin: 2rem 0 2rem 2em;
}
.mt-10 {
  margin-top: 10rem;
}
.content-box .label {
  width: 25%;
}

.content-box .desc {
  flex: 1;
}

.content-box .desc .desc-img {
  width: 14rem;
  height: 14rem;
  border-radius: 1rem;
  display: inline-block;
  margin-right: 1rem;
  background-color: aqua;
}
.drawer_footer {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  margin-right: 30px;
}

.select-num,
.add-money {
  font-size: 1.6rem;
  margin-right: 3rem;
}
.select-num span,
.add-money span {
  font-size: 2.3rem;
  font-weight: bold;
  color: #f87338;
  margin: 0 1rem;
}

.drawer_footer .footer-btn {
  line-height: 4rem;
  background-color: #f78c51;
  color: #fff;
  margin: 0 1rem;
  padding: 0 3rem;
  border-radius: 0.5rem;
  cursor: pointer;
  border: none;
  font-size: 1.6rem;
}
</style>